Skip to content

refactor(audience): SDK test pinning and sample-app custom events (SDK-277)#727

Open
ImmutableJeffrey wants to merge 10 commits intochore/sdk-272-pr-2-catalogues-and-test-infrafrom
chore/sdk-272-pr-3-test-pinning-and-sample-events
Open

refactor(audience): SDK test pinning and sample-app custom events (SDK-277)#727
ImmutableJeffrey wants to merge 10 commits intochore/sdk-272-pr-2-catalogues-and-test-infrafrom
chore/sdk-272-pr-3-test-pinning-and-sample-events

Conversation

@ImmutableJeffrey
Copy link
Copy Markdown
Collaborator

Summary

  • Pins Constants.LibraryName against the name field in package.json.
  • Pins backoff assertions in transport tests against Constants.HttpBackoff*Ms instead of magic numbers.
  • Covers IdentityTypeExtensions.ParseLowercaseString cases (known platform, unknown, null, empty, mixed case fallback to Custom).
  • Parametrises DistributionPlatform casing tests across all platform values.
  • Pins AudienceErrorMessages and AudienceArgumentMessages constants and formatters to their exact wording so a reword fails the build.
  • Adds Unity-only DeviceCollectorTests and SampleAppUxmlAlignmentTests drafts; both gated by UNITY_INCLUDE_TESTS and excluded from the headless dotnet build via Audience.Tests.csproj.
  • Adds TestEventNames for per-test event-name strings.
  • Adds SampleAppCustomEvents and SampleAppCustomEventPropertyKeys for the sample-app demo catalogue's custom event names and property keys.
  • Routes typed-event field lookups in SampleAppLiveFireTests through EventPropertyKeys.
  • No behaviour change. Wire format and OnError callback contract unchanged.

Linear: SDK-277

@ImmutableJeffrey ImmutableJeffrey requested review from a team as code owners May 3, 2026 07:17
@ImmutableJeffrey ImmutableJeffrey force-pushed the chore/sdk-272-pr-2-catalogues-and-test-infra branch from 1d1a56d to 9c7496b Compare May 3, 2026 07:40
@ImmutableJeffrey ImmutableJeffrey force-pushed the chore/sdk-272-pr-3-test-pinning-and-sample-events branch 2 times, most recently from 7ccd158 to 9c4da2e Compare May 3, 2026 07:43
@ImmutableJeffrey ImmutableJeffrey force-pushed the chore/sdk-272-pr-2-catalogues-and-test-infra branch from 9c7496b to 91f1783 Compare May 3, 2026 07:53
@ImmutableJeffrey ImmutableJeffrey force-pushed the chore/sdk-272-pr-3-test-pinning-and-sample-events branch from 9c4da2e to ba0bcf4 Compare May 3, 2026 07:54
ConstantsTests already pinned Constants.LibraryVersion against the
package.json "version" field so the two cannot silently drift; the
matching pin for Constants.LibraryName ("com.immutable.audience") and
package.json "name" was missing. Both feed context.library /
context.libraryVersion on every outgoing event, so a rename of either
side without the other would silently miscategorise events on the
backend.

Add a sibling LibraryName_MatchesPackageJson test that walks up to
the same package.json and asserts the two strings match. Reuses the
existing ReadPackageJson helper.

Follow-up to SDK-272 (centralisation of duplicated literals).
…off*Ms

HttpTransportTests pinned the backoff schedule with literal millisecond
numbers (5_000 / 10_000 / 20_000 / 40_000 / 60_000). Constants.HttpBackoff*Ms
now own those values, but the tests still hardcoded the numbers, so a
change to the constants would have flipped production behaviour while
the tests kept passing against the old expectations.

Switch every BackoffMs / NextAttemptAt assertion to derive from
Constants.HttpBackoff{1st,2nd,3rd,4th,Cap}Ms.

Follow-up to SDK-272 (centralisation of duplicated literals).
ParseLowercaseString was added in the SDK-272 stack as the inverse of
ToLowercaseString and consumed by the sample app to map wire strings
back to the enum. It had no direct test, so a typo in any of the eight
case branches or in the Custom fallback would land silently.

Add three parametrised cases:
- Each known enum value maps from its lowercase wire form.
- Mixed-case ("Steam", "STEAM", "Passport") still resolves
  via ToLowerInvariant, matching the documented behaviour.
- null, empty, and unknown values fall back to Custom (the parser
  never throws so producer code always gets a usable enum).

Follow-up to SDK-272 (centralisation of duplicated literals).
…l platforms

Init's lowercase-normalisation tests covered "Steam" / "STEAM" / "steam"
but not the other four public DistributionPlatforms values (Epic, GOG,
Itch, Standalone). Adding a sixth platform would land without coverage.

Add a parametrised Init_LowercasesDistributionPlatform_AcrossAllPublicValues
test that takes each public DistributionPlatforms constant, uppercases
it, runs Init, and asserts the canonical lowercase form is restored.

Follow-up to SDK-272 (centralisation of duplicated literals).
…sages

The two centralised message catalogues had no direct unit tests.
Behavioural tests observed wording loosely via Does.Contain assertions,
which let typos and partial rewords through.

Add MessagesTests.cs with one fixture per catalogue. Each constant /
formatter has an exact-string assertion. A reword anywhere in the
catalogue now fails the build.

Follow-up to SDK-272 (centralisation of duplicated literals).
@ImmutableJeffrey ImmutableJeffrey force-pushed the chore/sdk-272-pr-2-catalogues-and-test-infra branch from 91f1783 to 427f963 Compare May 3, 2026 07:58
@ImmutableJeffrey ImmutableJeffrey force-pushed the chore/sdk-272-pr-3-test-pinning-and-sample-events branch 4 times, most recently from cf5c443 to ea260bf Compare May 3, 2026 19:06
…ent drafts

Two Unity-only test fixtures the dotnet test runner cannot reach (DeviceCollector depends on
UnityEngine.SystemInfo / Application; SampleAppUxml needs Unity test framework gating). Both run
under the Unity Test Framework once the project is opened in the editor.

DeviceCollectorTests (src/Packages/Audience/Tests/Editor/, excluded from the headless dotnet build
by Audience.Tests.csproj's Compile Remove="Editor/**/*.cs" rule) pin DeviceCollector's emitted key
sets against GameLaunchPropertyKeys and ContextKeys, assert that no unknown keys leak in either
direction, and verify every string-typed value is capped at Constants.MaxFieldLength.

SampleAppUxmlAlignmentTests (examples/audience/Assets/SampleApp/Tests/ Runtime/, gated by the
existing UNITY_INCLUDE_TESTS define on the SampleApp.Tests asmdef) reads
Resources/AudienceSample.uxml as XML and asserts every SampleAppUi name and Css constant that is
slug-shaped (lowercase / dashes / no spaces) appears as a name= or class= attribute somewhere in the
markup. Runtime-only CSS toggles (state-warn, copied, narrow, has-value, etc.) are filtered by the
slug-shape heuristic so the test only flags constants that look like they should map directly to
UXML.

Both files compile cleanly. They will not run under dotnet test. Run them via Unity Test Runner.

Follow-up to SDK-272 (centralisation of duplicated literals).
Per the user's "everything random goes in a constant" stance, this is
applied against the previous session's recommendation that scenario
descriptors read better inline. Recording the override on the user's
explicit request.

Follow-up to SDK-272 (centralisation of duplicated literals).
…leAppCustomEvents

The sample-app demo catalogue (sign_up, sign_in, email_acquired,
wishlist_add, wishlist_remove, game_page_viewed, link_clicked,
screen_viewed) had its event-name strings inline at every call site.
A rename touches the catalogue, the screen_viewed Track call, and
each Unity live-fire test that drives the catalogue UI.

Move the eight names into a new internal SampleAppCustomEvents class
under the sample-app Scripts assembly. Update AudienceSample.Events.cs,
AudienceSample.cs (screen_viewed Track), and SampleAppLiveFireTests.cs
(button and field lookups by event name) to reference the constants.

Per the user's "everything random goes in a constant" stance,
applied against the previous session's recommendation that the demo
content read better inline. Recording the override on the user's
explicit request.

Follow-up to SDK-272 (centralisation of duplicated literals).
…mpleAppCustomEventPropertyKeys

The sample-app demo catalogue, screen_viewed Track call, and the
typed-event live-fire tests had property keys (method, source,
gameId, platform, gameName, slug, url, label, path) inline at every
call site. Each key duplicates between the catalogue's EventField
definition and the live-fire test's UI lookup.

Add SampleAppCustomEventPropertyKeys alongside SampleAppCustomEvents
(mirrors the SDK's EventPropertyKeys naming) and reference the
constants from AudienceSample.Events.cs, AudienceSample.cs (the
screen_viewed props dictionary), and SampleAppLiveFireTests.cs (the
TypedEventField field-name lookups).

Includes gameName and slug beyond the user's listed seven keys: same
inline-property-key category, same migration treatment.

Per the user's "everything random goes in a constant" stance,
applied against the previous session's recommendation that the demo
content read better inline. Recording the override on the user's
explicit request.

Follow-up to SDK-272 (centralisation of duplicated literals).
…d lookups in live-fire tests

SampleAppLiveFireTests filled the Resource, Purchase, and
MilestoneReached typed-event forms by looking up TextFields with
inline property-name strings ("currency", "amount", "value", "name").
The SDK already centralises these as EventPropertyKeys.Currency /
.Amount / .Value / .Name, made visible to the sample-app tests
through the existing InternalsVisibleTo grant.

Reference EventPropertyKeys.X from the five lookup sites instead of
re-typing the wire-format strings.

Discovered during the sample-app demo property-key centralisation
pass; kept separate because these keys belong to the SDK's typed-event
surface, not the sample-app demo catalogue.

Per the user's "everything random goes in a constant" stance.

Follow-up to SDK-272 (centralisation of duplicated literals).
@ImmutableJeffrey ImmutableJeffrey force-pushed the chore/sdk-272-pr-3-test-pinning-and-sample-events branch from ea260bf to 4bacd74 Compare May 3, 2026 19:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant